package com.cmbc.cps.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.cmbc.cos.cbs.wsclient.util.WsClientUtil;
import com.thitech.cps.CpsServiceFacade;
import com.thitech.cps.CpsServiceLocalBindingStub;
import com.thitech.cps.Message;

/**
 * <p> Title: CpsServiceFacadeImpl </p>
 * <p> Description:CPS服务，（MDS过数后调用此服务，发送消息通知取数 ） </p>
 * <p> Copyright: CMBC Copyright (c) 2015 </p>
 * <p> Company: CMBC </p>
 *
 * @author ylink_xiongbin
 *
 * @version 
 * @since 2015-4-20
 */
@Component("com.cmbc.cps.impl.CpsServiceFacadeImpl")
public class CpsServiceFacadeImpl implements CpsServiceFacade{
    private static final Logger log = LoggerFactory.getLogger(CpsServiceFacadeImpl.class);

    /**
      * @param  str  信号编码
      * @return Message  消息对象
     */
    @Override
    public Message sentMessage(String str) {
        String queryService="CpsService";
        Message message = null;
        try {
            CpsServiceLocalBindingStub stub = (CpsServiceLocalBindingStub) WsClientUtil.getStub(queryService);
            log.info("CpsServiceFacade_和EOD建立连接成功");         
            message = stub.ackEvent(str);
            String type = message.getType();
            if (!"E".equals(type)) {
                log.info("CpsServiceFacade_发送消息成功！");
            } else {
                log.info("CpsServiceFacade_发送消息失败:" + message.getCode() + "  " + message.getMessage());
            }
        }
        catch (Exception e) {
            log.info("CpsServiceFacade_发送消息异常！",e);
            e.printStackTrace();
        }
        return message;
    }
    
    public static void main(String[] args){
        CpsServiceFacadeImpl cps = new CpsServiceFacadeImpl();
        cps.sentMessage("MDS_EV_WAIT_CBS");
//        cps.sentMessage("MDS_EV_WAIT_BPO");
    }

}
